package com.winenine999.admin.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.winenine999.model.Purchasesub;
import com.winenine999.service.IPurchasesubService;
import com.winenine999.service.IWineproductService;

@Controller
@RequestMapping(value="/purchasesub")
public class PurchasesubController {
	@Autowired
	private IPurchasesubService Purchasesubservice;
	@Autowired
	private IWineproductService wineproductService;

	/**
	 * 
	 * @param phid
	 * @return
	 */
	@RequestMapping(value="/index")

	public String firstindex(Integer phid,Model model){
		model.addAttribute("phid",phid);
		return "message/purchasesub";
	}

	
	@RequestMapping(value="/in",method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> index(Integer phid){
		Map<String,Object> map=new HashMap<String,Object>();
		List<Map<String,Object>> maps=Purchasesubservice.getPurchasesubInfo(phid);
		map.put("aaData", maps);//查到的结果集
		map.put("recordsFiltered", maps.size());//总条数，用于计算页数
		map.put("recordsTotal",  maps.size());//总条数，用于页面显示：‘全部记录数  条’
		return map;
		
		
	}
	@RequestMapping(value="/showWinproductsByPhid",method=RequestMethod.POST)
	@ResponseBody
	public List<Map<String,Object>> showWinproductsByPhid(Integer phid){
		Map<String,Object> map=new HashMap<String,Object>();
		List lists=Purchasesubservice.findWidsByPhid(phid);
		List<Map<String,Object>> maps=wineproductService.selectWineProductsByIds(lists);
		return maps;				
	}
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ResponseBody
	public Integer add(Purchasesub purchasesub){
		Integer result=Purchasesubservice.insertSelective(purchasesub);

		return result;				
	}


}
